function import-statsio 
(
    [System.String]$inputFile = $(throw "'inputFile' Specify an input file containing the results of the 'SET STATISTICS IO' SQL Server command."),
    [System.String]$outputFile = $(throw "'outputFile' Specify an output file containing the results of the 'SET STATISTICS IO' SQL Server command in TSV format.")
    
)
{
    $inputText = [System.IO.File]::ReadAllText($inputFile)
    $regex = [System.Text.RegularExpressions.Regex] '(?im)Table\s+''(?<TableName>.+)''\.\s+Scan count\s+(?<ScanCount>\d+),\s+logical reads\s+(?<LogicalReads>\d+),\s+physical reads\s+(?<PhysicalReads>\d+),\s+read-ahead reads\s+(?<ReadAheadReads>\d+),\s+lob logical reads\s+(?<LobLogicalReads>\d+),\s+lob physical reads\s+(?<LobPhysicalReads>\d+),\s+lob read-ahead reads\s+(?<LobReadAheadReads>\d+)\.'
    $match = $regex.Match($inputText)
    
    if ($match.Groups.Count -eq 0)
    {
        write-error "No 'SET STATISTICS IO' information found in file '$inputFile'."
        return
    }

    $header = "{0}`t{1}`t{2}`t{3}`t{4}`t{5}`t{6}`t{7}`t{8}" -f "TableName", "ScanCount", "LogicalReads", "PhysicalReads", "ReadAheadReads", "LobLogicalReads", "LobPhysicalReads", "LobReadAheadReads", "CollectionTime"

    out-file -filepath $outputFile -inputobject $header -force

    while ($match.Success) 
    {
        $tableName = $match.Groups["TableName"].Value
        $scanCount = $match.Groups["ScanCount"].Value
        $logicalReads = $match.Groups["LogicalReads"].Value
        $physicalReads = $match.Groups["PhysicalReads"].Value
        $readAheadReads = $match.Groups["ReadAheadReads"].Value
        $logLogicalReads = $match.Groups["LobLogicalReads"].Value
        $lobPhysicalReads = $match.Groups["LobPhysicalReads"].Value
        $lobReadAheadReads = $match.Groups["LobReadAheadReads"].Value
        $collectionTime = [System.IO.File]::GetCreationTime($inputFile)
        
    	$output = "{0}`t{1}`t{2}`t{3}`t{4}`t{5}`t{6}`t{7}`t{8}" -f $tableName, $scanCount, $logicalReads, $physicalReads, $readAheadReads, $logLogicalReads, $lobPhysicalReads, $lobReadAheadReads, $collectionTime
        out-file -filepath $outputFile -inputobject $output -append -force
    	$match = $match.NextMatch()
    } 
    
    write-host "Formatted output written to $outputFile" -foregroundColor cyan

}
